package com.yxq.dao;

import com.yxq.util.DBUtil;
import com.yxq.entity.UserBean;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 */
public class UserDAO
{
    public UserBean findByName(String username)
    {
        Connection conn = null;
        PreparedStatement prep = null;
        ResultSet rs = null;

        try
        {
            conn = DBUtil.getConnection();
            prep = conn.prepareStatement("SELECT * FROM user WHERE username = ?");
            prep.setString(1, username);
            rs = prep.executeQuery();

            if (rs.next())
            {
                UserBean user = new UserBean();
                user.setUsername(username);
                user.setPassword(rs.getString("password"));

                return user;
            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            DBUtil.close(conn);
        }
        return null;
    }
}
